from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from hyzb.server.server import Server


# Create your views here.
class HyzbView(viewsets.ModelViewSet):
    # 指定权限类， 要求用户认证
    permission_classes = [IsAuthenticated]

    # 注入服务
    server = Server()

    def get_GHY_ADD(self, request):
        # 时间查询入参times，数据遵循国家数据时间筛选入参格式。
        times = request.query_params.get('times', 'LAST10')
        datas = self.server.get_GHY_ADD_datas(times)

        return Response(datas)

    def get_HYLRL(self, request):
        times = request.query_params.get('times', 'LAST10')
        datas = self.server.get_HYLRL_datas(times)
        return Response(datas)

    def get_HYTZ(self, request):
        times = request.query_params.get('times', 'LAST10')
        datas = self.server.get_HYTZ_datas(times)
        return Response(datas)

    def export_to_excel(self, request):
        return self.server.common.export_to_excel(request)

    def predict(self, request):
        return self.server.common.predict_data(request)
